<template>
	<wt-autocomplete
		v-model="currentValue"
		:multiple="multiSelect"
		:allow-add="true"
		:query="query"
		placeholder="请输入诊断关键字或拼音进行查询"
		:allow-use-without-add="true"
	></wt-autocomplete>
</template>
<script>
	import Vue from 'vue'
	import ElementUI from 'element-ui'
	import AutoComplete from 'winged/components/wt-autocomplete'

	Vue.use(ElementUI);
	Vue.component(AutoComplete.name, AutoComplete);

	export default {
		name: 'wt-case-selector',
		props: {
			value: [Array, String],
			multiSelect: {
				type: Boolean,
				default: true
			}
		},
		data: function () {
			return {
				currentValue: this.value,
				query: {
					url: 'doctor/patient/diagnoses/name',
					filterParam: 'diagnoses_name',
					method: 'GET',
					transfer: true,
					pagination: true,
					value: 'diagnosesName',
					allowAdd: true,
					addMethod: 'POST',
					addParam: 'diagnoses_name'
				}
			}
		},
		watch: {
			'value'(val, oldValue) {
				this.setCurrentValue(val);
			},
			'currentValue'(val, oldValue) {
				if (val != oldValue) {
					this.$emit('input', val);
				}
			}
		},
		methods: {
			setCurrentValue(value) {
				if (value === this.currentValue) return;
				this.currentValue = value;
			}
		}
	}
</script>